testsuite: Add theme-validate test
authorBenjamin Otte <otte@redhat.com>
Thu, 18 Apr 2019 00:18:42 +0000 (02:18 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 18 Apr 2019 00:28:42 +0000 (02:28 +0200)
The test just loads all of GTK's themes and makes sure they cause no
errors or warnings from the CSS parser.

testsuite/gtk/meson.build
testsuite/gtk/theme-validate.c [new file with mode: 0644]

index 97e5f47fce8f6a46c724d8c3638d6807eace6a58..246078c400c56888e6fcc250362c32d200cbd113 100644 (file)
@@ -52,6 +52,7 @@ tests = [
   ['templates'],
   ['textbuffer'],
   ['textiter'],
+  ['theme-validate'],
   ['transform'],
   ['treelistmodel'],
   ['treemodel', ['treemodel.c', 'liststore.c', 'treestore.c', 'filtermodel.c',
diff --git a/testsuite/gtk/theme-validate.c b/testsuite/gtk/theme-validate.c
new file mode 100644 (file)
index 0000000..e2e51e5
--- /dev/null
@@ -0,0 +1,70 @@
+#include <gtk/gtk.h>
+
+typedef struct _Theme Theme;
+
+struct _Theme
+{
+  const char *name;
+  const char *variant;
+};
+
+static void
+theme_parsing_error (GtkCssProvider *provider,
+                     GtkCssSection  *section,
+                     const GError   *error,
+                     gpointer        unused)
+{
+  char *s = gtk_css_section_to_string (section);
+
+  g_test_message ("Theme parsing error: %s: %s",
+                  s,
+                  error->message);
+
+  g_free (s);
+
+  g_test_fail ();
+}
+
+static void
+test_theme (gconstpointer data)
+{
+  const Theme *theme = data;
+  GtkCssProvider *provider;
+
+  provider = gtk_css_provider_new ();
+  g_signal_connect (provider, "parsing-error",
+                    G_CALLBACK (theme_parsing_error), NULL);
+  gtk_css_provider_load_named (provider, theme->name, theme->variant);
+  g_object_unref (provider);
+}
+
+int
+main (int argc, char *argv[])
+{
+  const Theme themes[] = {
+    { "Adwaita", NULL },
+    { "Adwaita", "dark" },
+    { "HighContrast", NULL },
+    { "HighContrast", "dark" }
+  };
+  guint i;
+
+  gtk_init ();
+  g_test_init (&argc, &argv, NULL);
+
+  for (i = 0; i < G_N_ELEMENTS (themes); i++)
+    {
+      char *testname;
+
+      if (themes[i].variant == NULL)
+        testname = g_strdup_printf ("/theme-validate/%s", themes[i].name);
+      else
+        testname = g_strdup_printf ("/theme-validate/%s-%s", themes[i].name, themes[i].variant);
+
+      g_test_add_data_func (testname, &themes[i], test_theme);
+
+      g_free (testname);
+    }
+
+  return g_test_run ();
+}